//use command:[cnpm config get prefix] to see path.
/*
 * NOTE:All js need to debug with alfred.
 */
var utils = require('/Users/Steve/tools/myGit/xNode/common/FooUtils.js');
var AlfredNode = require('alfred-workflow-nodejs');
var actionHandler = AlfredNode.actionHandler;
var moment = require('moment');
var workflow = AlfredNode.workflow;
workflow.setName("nodejs-workflow-urls");

var mysql = require('mysql');

var connection = require('../AlfredWorkflowMysqlServer.js');
var mysql = require('mysql');

actionHandler.onAction("record", function (query) {

    var currentDate = moment().toDate();
    var model = {
        last_check_time: currentDate
    };
    var array = (query + "").split(',');
    var id = array[0];
    var url = array[1];
    console.log(url);
    // console.log("id is:%s and url is:%",id,url);
    utils.openSystemDefaultBrowser(url);
    var sql = "update alfred_workflow_urls set ? where 1=1 and id = " + mysql.escape(id) + " ";
    connection.executeSql(sql, model);
    // connection.executeSql(sql, model).then(
    // function(rows) {
    // console.log(rows.affectedRows);
    // }).catch(function(err){
    // console.log(err);
    // });
});
AlfredNode.run();